﻿using FangPage.Common;
using FangPage.Core;
using FangPage.Data;
using ProjectManager.User.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectManager.User.Controller
{
    public class role_edit:FPController
    {
        protected string id = FPRequest.GetString("id");

        protected RoleInfo roleinfo = new RoleInfo();

        public override void Controller()
        {
            AuthInfo authinfo = Logins.Authorize();

            if (!authinfo.islogin)
            {
                FPResponse.WriteErr("对不起，您尚未登录或登录超时！");
                return;
            }

            if (!id.IsNullOrEmpty())
            {
                roleinfo = DbHelper.ExcuteModel<RoleInfo>(id);
            }

            if(ispost)
            {
                roleinfo = FPRequest.GetModel(roleinfo);

                if(roleinfo.id.IsNullOrEmpty())
                {
                    DbHelper.ExcuteInsert(roleinfo);

                    FPResponse.WriteSuccess("添加成功");
                }
                else
                {
                    DbHelper.ExcuteUpdate(roleinfo);

                    FPResponse.WriteSuccess("修改成功");
                }
            }
        }
    }
}
